﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AteckCsharp.Classes;
using System.Data;
using System.Web.Security;
namespace AteckCsharp.Employees
{
    public partial class UpdatePersonalInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DAL dal = new DAL();
                DataSet ds = new DataSet();
                String userId = Membership.GetUser(Session["User"].ToString()).ProviderUserKey.ToString();
                ds = dal.GetPersonalInfo(userId);
                if (ds != null)
                {
                    if (ds.Tables.Count > 0)
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            txtFirstName.Text = ds.Tables[0].Rows[0][1].ToString();
                            txtLastName.Text = ds.Tables[0].Rows[0][2].ToString();
                            txtStreet.Text = ds.Tables[0].Rows[0][3].ToString();
                            txtCity.Text = ds.Tables[0].Rows[0][4].ToString();
                            txtState.Text = ds.Tables[0].Rows[0][5].ToString();
                            txtZip.Text = ds.Tables[0].Rows[0][6].ToString();
                            DateTime dob = (DateTime)ds.Tables[0].Rows[0][7];
                            txtDob.Text = dob.Date.ToShortDateString();
                            txtPhoneNo.Text = ds.Tables[0].Rows[0][8].ToString();
                        }
                    }
                }

            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            AteckCsharp.Classes.PresonalInfo info = new AteckCsharp.Classes.PresonalInfo();
            info.userId = Membership.GetUser(Session["User"].ToString()).ProviderUserKey.ToString();
            info.FirstName = txtFirstName.Text;
            info.LastName = txtLastName.Text;
            info.Street = txtStreet.Text;
            info.City = txtCity.Text;
            info.Zip = txtZip.Text;
            info.State = txtState.Text;
            info.DOB = txtDob.Text;
            info.PhoneNo = txtPhoneNo.Text;
            DAL dal = new DAL();
            if (!dal.UpdatePersonalInfo(info))
            {
                //Error Log
            }
        }
    }
}